package com.example.firstboot.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.firstboot.service.TriageService;
import com.example.firstboot.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TriageController {

    @Autowired
    private TriageService triageService;

    //保存分诊问卷
    @PostMapping("/saveTriage")
    @ResponseBody
    public JsonResult saveTriage(@RequestBody JSONObject json){
        String username=(String) json.get("username");
        String idnumber=(String) json.get("idnumber");
        String phone=(String) json.get("phone");
        String temperature=(String) json.get("temperature");
        String travel_history=(String) json.get("travel");
        String contact_history=(String) json.get("contact");
        String job=(String) json.get("job");
        String symptom=(String) json.get("symptom");
        String nucleic_acid=(String) json.get("nucleic");
        String date=(String) json.get("date");
        Integer i=triageService.addTriage(username,idnumber,phone,temperature,travel_history,
                contact_history,job,symptom,nucleic_acid,date);
        if(i>0){
            return new JsonResult();
        }else {
            return new JsonResult(-1,"数据保存失败");
        }
    }

    //用户付费后，给用户添加核酸检测项目
    @PostMapping("/saveTriageCheck")
    @ResponseBody
    public JsonResult saveTriageCheck(@RequestBody JSONObject json){
        String account=(String) json.get("account");
        String checkId=(String) json.get("checkId");
        Integer i=triageService.addTriageCheck(account,checkId);
        if(i>0){
            return new JsonResult();
        }else {
            return new JsonResult(-1,"数据保存失败");
        }
    }
}
